package updown.data;

import cn.hutool.core.thread.ExecutorBuilder;
import com.alibaba.ttl.threadpool.TtlExecutors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**
 * <p>Title: updown.data </p>
 * <p>Description:updown: - 线程池工具类 </p>
 *
 * @Author:jiangkaixin
 * @Date:2022/1/13
 * @Version: 1.0
 */
@Slf4j
@Component
public class ExecutorPoolUtil {
    public static ExecutorService executor;
    public static ScheduledExecutorService schedulePool;

    static {
        ThreadPoolExecutor poolExecutor = ExecutorBuilder.create()
                .setCorePoolSize(10)
                .setMaxPoolSize(20)
                .setKeepAliveTime(5, TimeUnit.SECONDS)
                .setWorkQueue(new LinkedBlockingQueue<>(256))
                .build();
        executor = TtlExecutors.getTtlExecutorService(poolExecutor);
        log.info("创建 executor");

        ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(20);
        schedulePool = TtlExecutors.getTtlScheduledExecutorService(scheduledExecutorService);
        log.info("创建 schedulePool");
    }
}
